package com.jm.api;

import com.jm.anno.Grade;
import com.jm.bean.GradeParam;
import com.jm.common.conf.api.ApiResult;
import com.jm.constant.SysApiConstant;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.lang.reflect.Field;

/**
 * @author kong
 */
@Slf4j
@Tag(name = "测试获取注解")
@RestController
@RequestMapping(SysApiConstant.OPEN_API)
public class TestAnnoApi {

    @GetMapping("/test")
    @ApiResult
    public void login(@RequestBody GradeParam param) throws IllegalAccessException {
        Field[] fields = param.getClass().getDeclaredFields();
        for (Field field : fields) {
            //设置可访问权限
            field.setAccessible(true);
            //获取指定注解
            Grade grade = field.getDeclaredAnnotation(Grade.class);
            //获取注解值
            String v = grade.value();
            //获取属性值
            Object o = field.get(param);
            log.debug("注解值:{} 属性值:{}", v, o);
        }

    }


}
